<?php

// We need the site name from config
require_once('./includes/config.php');
	
require_once('./includes/database.php');
require_once('./includes/session.php');
require_once('./includes/users.php');
db_setup();
session_continue();

// If user submitted info
if(isset($_POST['username']))
{
	$username = mysql_real_escape_string($_POST['username']);
	$password = mysql_real_escape_string($_POST['password']);
	
	user_login($username, $password, session_id());
	$user = user_logged_in(session_id());
	
	if ($user->id != 0)
	{
		header('Location: index.php');
	}
	else
	{
		echo 'Failed to login.';
	}
}
// Otherwise show the form
else
{	
	// Smarty code, passes variables to display
	require_once('./includes/smarty/Smarty.class.php');
	$smarty = new Smarty();
	$smarty->assign('page_title', $site_name.' | Index');
	$smarty->assign('root_folder', $root_folder);
	$smarty->display('login.tpl');
}

?>